package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRegister;
import com.ruoyi.system.service.ISysRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/register")
public class SysRegisterPController extends BaseController {
    @Autowired
    private ISysRegisterService registerService;

    /**
     * 获取检查费用项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRegister register) {
        startPage();
        List<SysRegister> list = registerService.selectRegisterList(register);
        return getDataTable(list);
    }

    /**
     * 新增挂号信息
     */
    @PreAuthorize("@ss.hasPermi('system:register:add')")
    @Log(title = "挂号信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysRegister register) {
        register.setCreateBy(getUsername());
        return toAjax(registerService.insertRegister(register));
    }

    /**
     * 根据id查询挂号信息
     */
    @PreAuthorize("@ss.hasPermi('system:register:query')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult getInfo(@PathVariable Long registerId) {
        return success(registerService.selectRegisterById(registerId));
    }

    @PreAuthorize("@ss.hasPermi('system:register:edit')")
    @Log(title = "挂号信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysRegister register) {
        register.setUpdateBy(getUsername());
        return toAjax(registerService.updateRegisterById(register));
    }

    @PreAuthorize("@ss.hasPermi('system:register:remove')")
    @Log(title = "删除挂号信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{registerIds}")
    public AjaxResult remove(@PathVariable Long[] registerIds) {
        return toAjax(registerService.deleteRegisterByIds(registerIds));
    }

}
